<template>
  <page-view class="page-view" :title="false" style="user-select: none">
    <div slot="headerContent">
      <a-breadcrumb class="s-breadcrumb">
        <a-breadcrumb-item>资产管理</a-breadcrumb-item>
        <a-breadcrumb-item><router-link to="/property/plan">资产盘点计划</router-link></a-breadcrumb-item>
        <a-breadcrumb-item><router-link :to="`/property/plan/child/${name}/${id}`">{{ name }}</router-link></a-breadcrumb-item>
        <a-breadcrumb-item>{{ childName }}</a-breadcrumb-item>
      </a-breadcrumb>
    </div>

    <a-card class="s-card">
      <a-spin :spinning="sending">

        <a-tabs v-model="tabIndex" animated type="card">
          <a-tab-pane :key="0" tab="子计划明细">
            <s-table
              ref="infoTable"
              class="s-table"
              bordered
              :columns="infoColumns"
              :data="loadInfo"
              :locale="{ emptyText: '暂无数据' }"
              :show-pagination="false"
              :alert="false"
              row-key="id"
            >
              <template slot="action" slot-scope="item">
                <div class="action-container">
                  <span class="danger-link" @click="handleDel(item)">删除</span>
                  <span class="success-link" @click="showDetail(item)">物品明细</span>
                </div>
              </template>
            </s-table>
          </a-tab-pane>

          <a-tab-pane :key="1" tab="数据明细" style="position: relative">
            <a-tabs v-model="detailTabIndex" animated type="card">
              <template slot="tabBarExtraContent">
                <a-button class="primary-btn" :loading="sending" @click="handleExport">导出报表</a-button>
              </template>
              <a-tab-pane :key="0" tab="子计划汇总表">
                <s-table
                  ref="childTable-0"
                  class="s-table"
                  bordered
                  :columns="allColumns"
                  :data="loadAll"
                  :locale="{ emptyText: '暂无数据' }"
                  :alert="false"
                  :show-pagination="false"
                  row-key="k"
                >
                  <template slot="action" slot-scope="item">
                    <div class="action-container">
                      <span class="success-link" @click="showDataDetail(item)">详情</span>
                    </div>
                  </template>
                </s-table>
              </a-tab-pane>

              <a-tab-pane :key="1" tab="子区域汇总表">
                <s-table
                  ref="childTable-1"
                  class="s-table"
                  bordered
                  :columns="allColumns"
                  :data="loadAll"
                  :locale="{ emptyText: '暂无数据' }"
                  :alert="false"
                  :show-pagination="false"
                  row-key="k"
                >
                  <template slot="action" slot-scope="item">
                    <div class="action-container">
                      <span class="success-link" @click="showDataDetail(item)">详情</span>
                    </div>
                  </template>
                  <template slot="footer">
                    <a-table
                      v-if="allCount.length"
                      class="s-table footer-table"
                      bordered
                      :columns="allColumns"
                      :data-source="allCount"
                      :show-header="false"
                      :pagination="false"
                      row-key="goodsName"
                    >
                      <template slot="code" slot-scope="text">
                        <span style="opacity: 0">{{ text }}</span>
                      </template>
                      <template slot="deptName" slot-scope="text">
                        <span style="opacity: 0">{{ text }}</span>
                      </template>
                      <template slot="status" slot-scope="text">
                        <span style="opacity: 0">{{ text }}</span>
                      </template>
                      <template slot="action">
                        <div class="action-container">
                          <span class="success-link" style="opacity: 0">详情</span>
                        </div>
                      </template>
                    </a-table>
                  </template>
                </s-table>
              </a-tab-pane>

              <a-tab-pane
                v-for="(tab, index) in infoList"
                :key="index + 2"
                :tab="`${tab.deptName || ''}明细表`"
              >
                <a-row>
                  <a-col :span="8">
                    <a-form-item label="子区域" v-bind="formItemLayout">
                      <a-select v-model="targetAreaId" style="width: 100%" @change="selectArea">
                        <a-select-option
                          v-for="item in areaList"
                          :key="item.id"
                          :value="item.id"
                        >{{ item.name }}</a-select-option>
                      </a-select>
                    </a-form-item>
                  </a-col>
                </a-row>
                <s-table
                  :ref="`childTable-${index + 2}`"
                  class="s-table"
                  bordered
                  :columns="childColumns"
                  :data="loadChild"
                  :locale="{ emptyText: '暂无数据' }"
                  :alert="false"
                  :show-pagination="false"
                  row-key="k"
                >
                  <template slot="lastBalance" slot-scope="text,item">
                    <span :class="[item.status === '异常' ? 'danger-color' : '']">{{ text }}</span>
                  </template>
                  <template slot="receive" slot-scope="text,item">
                    <span :class="[item.status === '异常' ? 'danger-color' : '']">{{ text }}</span>
                  </template>
                  <template slot="reduce" slot-scope="text,item">
                    <span :class="[item.status === '异常' ? 'danger-color' : '']">{{ text }}</span>
                  </template>
                  <template slot="quantity" slot-scope="text,item">
                    <a-input-number
                      v-if="item.editable"
                      v-model="item.quantity"
                      class="width-fix"
                      :min="-10000000000000000"
                      :max="10000000000000000"
                      placeholder="请输入"
                    />
                    <span v-else :class="[item.status === '异常' ? 'danger-color' : '']">{{ text }}</span>
                  </template>
                  <template slot="balance" slot-scope="text,item">
                    <span :class="[item.status === '异常' ? 'danger-color' : '']">{{ text }}</span>
                  </template>
                  <template slot="status" slot-scope="text,item">
                    <span :class="[item.status === '异常' ? 'danger-color' : '']">{{ text }}</span>
                  </template>
                  <template slot="action" slot-scope="item">
                    <div v-if="!item.editable" class="action-container">
                      <span class="success-link" @click="showDataDetail(item)">详情</span>
                      <span v-if="item.status === '异常'" class="primary-link" @click="clickEdit(item, 1)">纠正</span>
                    </div>
                    <div v-else class="action-container">
                      <span class="success-link" @click="handleSave(item)">保存</span>
                      <span class="danger-link" @click="clickEdit(item)">取消</span>
                    </div>
                  </template>
                  <template slot="footer">
                    <a-table
                      v-if="childCount[detailTabIndex] && childCount[detailTabIndex].length"
                      class="s-table footer-table"
                      bordered
                      :columns="childColumns"
                      :data-source="childCount[detailTabIndex]"
                      :show-header="false"
                      :pagination="false"
                      row-key="goodsName"
                    >
                      <template slot="userName" slot-scope="text">
                        <span style="opacity: 0">{{ text }}</span>
                      </template>
                      <template slot="status" slot-scope="text">
                        <span style="opacity: 0">{{ text }}</span>
                      </template>
                      <template slot="updatedDate" slot-scope="text">
                        <span style="opacity: 0">{{ text }}</span>
                      </template>
                      <template slot="action" slot-scope="item">
                        <div class="action-container">
                          <span class="success-link" style="opacity: 0">详情</span>
                          <span v-if="item.status === '异常'" class="primary-link" style="opacity: 0">纠正</span>
                        </div>
                      </template>
                    </a-table>
                  </template>
                </s-table>
              </a-tab-pane>
            </a-tabs>
          </a-tab-pane>

        </a-tabs>

      </a-spin>
    </a-card>

    <a-modal
      v-model="showDataModal"
      centered
      :title="modalTitle"
      :footer="null"
      width="70%"
    >
      <a-col :span="8" style="margin-bottom: 20px">
        <div v-if="/0/.test(detailTabIndex)">子计划名称：{{ childName }}</div>
        <div v-else>总负责人：{{ target.username || '-' }}</div>
      </a-col>
      <a-col :span="8" style="margin-bottom: 20px">盘点资产名称：{{ target.goodsName || '-' }}</a-col>
      <a-col :span="8" style="margin-bottom: 20px">盘点区域：{{ target.deptName || '-' }}</a-col>
      <a-col :span="8" style="margin-bottom: 10px">盘点明细：</a-col>
      <a-table
        class="s-table"
        bordered
        :scroll="{ y: 400 }"
        :columns="detailTabIndex > 1 ? areaColumns : [dataColumns, areaAllColumns][detailTabIndex]"
        :data-source="$get(target, detailTabIndex > 1 ? 'assetsInventoryLogVoList' : 'assetsInventoryVoList', [])"
        :locale="{ emptyText: '暂无数据' }"
        :pagination="false"
        row-key="name"
      />
    </a-modal>

    <a-modal
      v-model="showItemModal"
      centered
      title="盘点物品"
      :footer="null"
    >
      <a-table
        class="s-table"
        bordered
        :columns="[{ title: '物品明细', dataIndex: 'name', align: 'center' }]"
        :data-source="itemList"
        :locale="{ emptyText: '暂无数据' }"
        :pagination="false"
        :scroll="{ y: 400 }"
        row-key="name"
      />
    </a-modal>

  </page-view>
</template>

<script>
import { mapState } from 'vuex'
import { PageView, STable } from '@/components'

const statusMaps = ['-', '待确认', '待盘点', '待核查', '已完成']

export default {
  name: 'Detail',
  components: { PageView, STable },
  inject: ['formItemLayout'],
  props: {
    name: {
      type: String,
      default: ''
    },
    id: {
      type: String,
      default: ''
    },
    childName: {
      type: String,
      default: ''
    },
    childId: {
      type: String,
      default: ''
    },
    isDetail: {
      type: Boolean,
      default: false
    }
  },
  validate ({ params }) { return params.id && params.childId },

  async fetch ({ app, store }) {
    const { dispatch, $get } = store
    const list = [
      { fn: app.$teacherListFunc }
    ]
    // if (!store.$get(store, 'state.basic.teacherList.length')) app.$teacherListFunc()
    if (!$get(store, 'state.basic.deptList.length')) list.push({ fn: app.$departmentListFunc })
    if (!$get(store, 'state.basic.areaList.length')) list.push({ fn: app.$areaListFunc })
    await app.$requestList(list)
    dispatch('basic/setDeptArea')
  },

  data () {
    return {
      sending: false,
      tabIndex: 0,
      detailTabIndex: 0,

      showDataModal: false,
      modalTitle: '',
      showItemModal: false,
      itemList: [],

      tableList: [], // 用于判断是否有数据可导出

      infoColumns: [
        { title: '盘点区域', align: 'center', dataIndex: 'deptName' },
        { title: '盘点责任人', align: 'center', dataIndex: 'userName' },
        { title: '发起日期', align: 'center', dataIndex: 'createdDate' },
        { title: '截止日期', align: 'center', dataIndex: 'deadlineDate' },
        { title: '盘点状态', align: 'center', dataIndex: 'statusName' },
        { title: '盘点发起人', align: 'center', dataIndex: 'createdName' },
        { title: '操作', align: 'center', width: '150px', scopedSlots: { customRender: 'action' }}
      ],
      infoList: [],

      allColumns: [
        { title: '物品编号', width: '12%', align: 'center', dataIndex: 'code', scopedSlots: { customRender: 'code' }},
        { title: '物品名称', width: '12%', align: 'center', dataIndex: 'goodsName' },
        { title: '盘点区域', width: '12%', align: 'center', dataIndex: 'deptName', scopedSlots: { customRender: 'deptName' }},
        { title: '上期结存', width: '12%', align: 'center', dataIndex: 'lastBalance' },
        { title: '本期领入', width: '12%', align: 'center', dataIndex: 'receive' },
        { title: '本期减少', width: '12%', align: 'center', dataIndex: 'reduce' },
        { title: '本期结存', width: '12%', align: 'center', dataIndex: 'balance' },
        { title: '库存状态', width: '12%', align: 'center', dataIndex: 'status', scopedSlots: { customRender: 'status' }},
        { title: '操作', width: '4%', align: 'center', scopedSlots: { customRender: 'action' }}
      ],
      allCount: [],

      childColumns: [
        { title: '盘点负责人', width: '10%', align: 'center', dataIndex: 'userName', scopedSlots: { customRender: 'userName' }},
        { title: '物品名称', width: '10%', align: 'center', dataIndex: 'goodsName' },
        { title: '上期结存', width: '10%', align: 'center', dataIndex: 'lastBalance', scopedSlots: { customRender: 'lastBalance' }},
        { title: '本期领入', width: '10%', align: 'center', dataIndex: 'receive', scopedSlots: { customRender: 'receive' }},
        { title: '本期减少', width: '10%', align: 'center', dataIndex: 'reduce', scopedSlots: { customRender: 'reduce' }},
        { title: '上报数量', width: '10%', align: 'center', dataIndex: 'quantity', scopedSlots: { customRender: 'quantity' }},
        { title: '本期结存', width: '10%', align: 'center', dataIndex: 'balance', scopedSlots: { customRender: 'balance' }},
        { title: '库存状态', width: '10%', align: 'center', dataIndex: 'status', scopedSlots: { customRender: 'status' }},
        { title: '上报时间', width: '15%', align: 'center', dataIndex: 'updatedDate', scopedSlots: { customRender: 'updatedDate' }},
        { title: '操作', align: 'center', scopedSlots: { customRender: 'action' }}
      ],
      childCount: [[], []],
      targetAreaId: undefined,
      areaId: [undefined, undefined],
      areaList: [],

      target: {},
      dataColumns: [
        { title: '总负责人', align: 'center', width: '15%', dataIndex: 'personName' },
        { title: '盘点时间', align: 'center', width: '30%', dataIndex: 'deadlineDate' },
        { title: '上期结存', align: 'center', width: '13%', dataIndex: 'lastBalance' },
        { title: '本期结存', align: 'center', width: '13%', dataIndex: 'balance' },
        { title: '盘点子区域', align: 'center', dataIndex: 'deptName' }
      ],
      areaAllColumns: [
        { title: '盘点负责人', align: 'center', width: '15%', dataIndex: 'userName' },
        { title: '盘点时间', align: 'center', width: '25%', dataIndex: 'deadlineDate' },
        { title: '上期结存', align: 'center', width: '10%', dataIndex: 'lastBalance' },
        { title: '本期结存', align: 'center', width: '10%', dataIndex: 'balance' },
        { title: '状态', align: 'center', width: '10%', dataIndex: 'status' },
        { title: '盘点区域', align: 'center', width: '15%', dataIndex: 'deptName' },
        { title: '总负责人', align: 'center', dataIndex: 'personName' }
      ],
      areaColumns: [
        { title: '操作人', align: 'center', width: '15%', dataIndex: 'username' },
        { title: '操作时间', align: 'center', width: '30%', dataIndex: 'updatedDate' },
        { title: '上报数量', align: 'center', width: '15%', dataIndex: 'quantity' },
        { title: '备注', align: 'center', dataIndex: 'remark' }
      ],

      tempEdit: {}
    }
  },

  computed: {
    ...mapState({
      areaMaps: state => state.basic.areaMaps,
      teacherMaps: state => state.basic.teacherMaps
    })
  },

  watch: {
    async detailTabIndex (index) {
      this.targetAreaId = this.areaId[index] || undefined
      this.areaList.splice(0)
      this.refresh(`childTable-${index}`)
    },

    isDetail: {
      handler (bool) {
        if (!/false|0|null|undefined/.test(bool) && this.tabIndex !== 1) this.tabIndex = 1
      },
      immediate: true
    }
  },

  methods: {
    selectArea (id) {
      this.areaId.splice(this.detailTabIndex, 1, id)
      if (id) this.refresh(`childTable-${this.detailTabIndex}`)
    },

    async handleSave (item) {
      if (!item.id || this.sending) return false
      const { refresh, detailTabIndex, $axios, $message, $get } = this
      this.$toggleSending(1)
      const res = await $axios.post('api/assetsInventory/update', { id: item.id, quantity: item.quantity })
        .then(res => res).catch(e => [])
      $message.destroy()
      if ($get(res, 'data.code') !== '000000') return $message.error($get(res, 'data.mesg', '请稍后再试'))
      $message.info('纠正成功')
      this.$toggleSending()
      refresh(`childTable-${detailTabIndex}`)
    },

    clickEdit (item, bool) {
      const data = {}
      const { detailTabIndex, tempEdit, $clonedeep } = this
      if (!tempEdit[detailTabIndex]) tempEdit[detailTabIndex] = {}
      if (bool) {
        tempEdit[detailTabIndex][item.id] = $clonedeep(item)
      } else {
        Object.assign(data, tempEdit[detailTabIndex][item.id])
      }
      Object.assign(item, { ...data, editable: !!bool })
      this.$forceUpdate()
    },

    // 区域明细表 detailTabIndex > 1
    async loadChild () {
      const { $axios, $get, childId, childCount, infoList, detailTabIndex, teacherMaps, $moment, areaList, areaId, tableList } = this
      tableList.splice(0)
      if (!areaList.length) {
        const deptId = infoList[detailTabIndex - 2].deptId
        this.$toggleSending(1)
        if (detailTabIndex > 1) {
          // const list = await $axios.post('api/area/queryAll', { dept_id: deptId })
          const list = await $axios.post('api/area/queryAll', { pid: deptId })
            .then(res => $get(res, 'data.data', []))
            .catch(e => [])
          areaList.push(...list)
          if (list[0] && !areaId[detailTabIndex]) {
            areaId.splice(detailTabIndex, 1, list[0].id)
            this.targetAreaId = list[0].id
          }
        }
        this.$toggleSending()
      }

      const resData = { data: [] }
      const detail_id = infoList[detailTabIndex - 2].id
      const deptId = infoList[detailTabIndex - 2].deptId
      const dept_id = this.targetAreaId || this.targetAreaId === 0 ? this.targetAreaId : deptId || deptId === 0 ? deptId : -1
      const param = { plan_id: childId / 1, detail_id, dept_id }
      childCount.splice(detailTabIndex, 1, [])
      let userName = '-'
      let updatedDate = '-'
      let status = '-'
      this.$toggleSending(1)
      return $axios.post('api/assetsInventory/queryCli', param).then(res => {
        this.$toggleSending()
        const list = $get(res, 'data.data', [])
        resData.data = list.map((i, k) => {
          const data = { k, editable: undefined }
          const keys = ['code', 'goodsName', 'status', 'deptName']
          keys.forEach(key => { if (!i[key]) data[key] = '-' })
          if (!i.userName && i.userId) data.userName = $get(teacherMaps, `${i.userId}.name`, '-')
          if (!i.createdBy) data.createdName = $get(teacherMaps, `${i.createdBy}.name`, '-')
          if (!i.quantity) data.quantity = 0
          data.updatedDate = i.updatedTime ? $moment(i.updatedTime).format('YYYY.MM.DD HH:mm') : '-'
          if (i.userName && String(i.userName).length > String(userName).length) userName = i.userName
          if (i.status && String(i.status).length > String(status).length) status = i.status
          if (data.updatedDate && String(data.updatedDate).length > String(updatedDate).length) updatedDate = data.updatedDate
          return Object.assign(i, data)
        }).filter(i => i.goodsName !== '小计')
        tableList.push(...resData.data)
        const countList = list.filter(i => i.goodsName === '小计')
          .map(i => Object.assign(i, { status, updatedDate, userName }))
        childCount.splice(detailTabIndex, 1, countList)
        return resData
      }).catch(e => {
        this.$toggleSending()
        return resData
      })
    },

    // 汇总表 detailTabIndex < 2
    loadAll () {
      const { $axios, $get, childId, allCount, detailTabIndex, tableList } = this
      tableList.splice(0)
      const resData = { data: [] }
      const param = { plan_id: childId / 1 }
      allCount.splice(0)
      const url = detailTabIndex > 0 ? 'queryCli' : 'queryCliSummary'
      let countCode = '-'
      let countDeptName = '-'
      let countStatus = '-'
      this.$toggleSending(1)
      return $axios.post(`api/assetsInventory/${url}`, param).then(res => {
        this.$toggleSending()
        const list = $get(res, 'data.data', [])
        resData.data = list.map((i, k) => {
          const data = { k }
          const keys = ['code', 'goodsName', 'deptName', 'status', 'userName']
          keys.forEach(key => { if (!i[key]) data[key] = '-' })
          if (i.code && String(i.code).length > String(countCode).length) countCode = i.code
          if (i.deptName && String(i.deptName).length > String(countDeptName).length) countDeptName = i.deptName
          if (i.status && String(i.status).length > String(countStatus).length) countStatus = i.status
          return Object.assign(i, data)
        }).filter(i => i.goodsName !== '小计')
        allCount.push(...list.filter(i => i.goodsName === '小计').map(i => Object.assign(i, { code: countCode, deptName: countDeptName, status: countStatus })))
        tableList.push(...resData.data)
        return resData
      }).catch(e => {
        this.$toggleSending()
        return resData
      })
    },

    // 计划明细 tabIndex: 0
    loadInfo () {
      const { $axios, $get, $moment, childId, teacherMaps, infoList, areaMaps } = this
      const resData = { data: [] }
      const param = { pageSize: -1, plan_id: childId / 1 }
      infoList.splice(0)
      return $axios.post('api/assetsInventoryPlanDetail/query', param).then(res => {
        resData.data = $get(res, 'data.data.dataList', []).map(i => {
          const data = {}
          if (!i.userName) data.userName = $get(teacherMaps, `${i.userId}.name`, '-')
          if (!i.createdName) data.createdName = $get(teacherMaps, `${i.createdBy}.name`, '-')
          data.createdDate = i.createdTime ? $moment(i.createdTime).format('YYYY.MM.DD') : '-'
          data.deadlineDate = i.deadline ? $moment(i.deadline).format('YYYY.MM.DD') : '-'
          data.deptName = i.deptName || '-'
          data.statusName = statusMaps[i.status] || '-'
          if (data.deptName === '-' && i.deptId) data.deptName = $get(areaMaps, `${i.deptId}.areaName`, '-')
          return Object.assign(i, data)
        })
        infoList.push(...resData.data)
        return resData
      }).catch(e => resData)
    },

    // 导出报表
    async handleExport () {
      const { detailTabIndex, $moment, infoList, childId, areaList, targetAreaId, $get, $message, tableList } = this
      $message.destroy()
      if (!tableList || !tableList.length) return $message.error('没有可导出数据，请刷新或稍后再试')
      const nowTime = $moment().format('YYYY-MM-DD HH:mm:ss')
      const param = { plan_id: childId / 1 }
      if (detailTabIndex > 1) {
        const deptId = infoList[detailTabIndex - 2].deptId
        const dept_id = this.targetAreaId || this.targetAreaId === 0 ? this.targetAreaId : deptId || deptId === 0 ? deptId : -1
        Object.assign(param, { detail_id: infoList[detailTabIndex - 2].id, dept_id })
      }
      let name = ['子计划', '子区域', ...infoList.map(i => i.deptName)][detailTabIndex]
      if (detailTabIndex > 1) name += `_${$get(areaList.filter(i => i.id === targetAreaId), '0.name', '')}`
      this.$toggleSending(1)
      const url = detailTabIndex > 0 ? 'exportQueryCli' : 'exportQueryCliSummary'
      await this.$exportFile({
        url: `api/assetsInventory/${url}`,
        param,
        fileName: `${name}${detailTabIndex > 1 ? '明细' : '汇总'}表_${nowTime}`
      })
      this.$toggleSending()
    },

    handleDel ({ id = -1 }) {
      if (id === -1) return false
      const { deleteItem } = this
      this.$confirm({
        centered: true,
        maskClosable: true,
        title: '提示',
        content: '确定删除？',
        onOk () {
          deleteItem(id)
        }
      })
    },

    async deleteItem (id) {
      const { $axios, $message, $get, refresh } = this
      this.$toggleSending(1)
      const res = await $axios.delete(`api/assetsInventoryPlanDetail/${id}`).then(res => res).catch(e => false)
      $message.destroy()
      this.$toggleSending()
      if ($get(res, 'data.code') === -1) return $message.error($get(res, 'data.mesg', '请稍后再试'))
      $message.info('操作成功')
      refresh()
    },

    refresh (name = 'infoTable') {
      const { detailTabIndex, $refs, $get, tempEdit } = this
      if (name.includes('childTable') && detailTabIndex > 1) tempEdit[detailTabIndex] = {}
      let table = $get($refs, name, {})
      table = table[0] || table
      table && table.refresh && table.refresh()
    },

    // 物品明细
    async showDetail ({ id = -1 }) {
      if (id === -1) return false
      const { $axios, $get, itemList } = this
      this.$toggleSending(1)
      itemList.splice(0)
      const items = await $axios.post('api/assetsInventoryPlanDetail/getPlanGoods', { id }).then(res => $get(res, 'data.data', [])).catch(e => [])
      itemList.push(...items)
      console.log(itemList)
      this.$toggleSending()
      this.showItemModal = true
    },

    // 详情
    async showDataDetail ({ goodsId = -1, inventoryIds = -1, id = -1, planId = -1, goodsName = '', deptName = '' }) {
      const { childId, $axios, $get, $moment, detailTabIndex, childName, targetAreaId, areaList } = this
      const firName = `${detailTabIndex > 1 ? $get(areaList.filter(i => i.id === targetAreaId), '0.name', '') : [childName, deptName][detailTabIndex]}`
      this.modalTitle = `【${firName}${goodsName ? ' —— ' + goodsName : ''}】${detailTabIndex > 1 ? '操作' : '盘点'}明细`
      const param = { plan_id: childId / 1, goods_id: goodsId }
      if (/0|1/.test(detailTabIndex)) Object.assign(param, { inventory_ids: inventoryIds })
      else if (detailTabIndex > 1) Object.assign(param, { id })
      this.$toggleSending(1)
      const url = detailTabIndex > 1 ? 'getInventoryLog' : ['queryCliSummaryDetail', 'queryAreaSummaryDetail'][detailTabIndex]
      const data = await $axios.post(`api/assetsInventory/${url}`, param)
        .then(res => $get(res, 'data.data', {}))
        .catch(e => {})
      const key = detailTabIndex > 1 ? 'assetsInventoryLogVoList' : 'assetsInventoryVoList'
      if (!data[key]) data[key] = []
      data[key].forEach(i => {
        const data = {}
        if (detailTabIndex > 1) data.updatedDate = i.updatedTime ? $moment(i.updatedTime).format('YYYY-MM-DD HH:mm') : '-'
        else data.deadlineDate = i.deadline ? $moment(i.deadline).format('YYYY-MM-DD HH:mm') : '-'
        const keys = ['personName', 'deptName', 'status', 'userName', 'remark', 'username']
        keys.forEach(key => { if (!i[key]) data[key] = '-' })
        if (detailTabIndex > 1 && !i.quantity && i.quantity !== 0) data.quantity = '-'
        Object.assign(i, data)
      })
      if (!data.deptName) data.deptName = detailTabIndex > 1 ? $get(areaList.filter(i => i.id === targetAreaId), '0.name', '') : deptName
      this.target = data
      this.$toggleSending()
      this.showDataModal = true
    }
  }
}
</script>

<style lang="less" scoped>
  .ant-table-footer {
    padding: 0 1px;
  }

  /deep/ .ant-table-footer {
    padding: 0;
    margin-top: -1px;
    border: 0 !important;
  }

  .danger-color {
    color: @red;
  }
</style>
